﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace ProMvc.Helpers
{
    public static class HtmlHelpers
    {
        public static MvcHtmlString Pager(this HtmlHelper helper, int startPage, int currentPage, int totalPages, int pagesToShow)
        {
            System.Web.Routing.RouteData routeData = helper.ViewContext.RouteData;
            
            System.Web.Routing.RouteValueDictionary values = routeData.Values;
            
            //StringBuilder html =
            //Enumerable.Range(startPage, totalPages)
            //.Where(i => (currentPage - pagesToShow) < i & i < (currentPage + pagesToShow))
            //.Aggregate(new StringBuilder(@"<div class=""pager-bar""><span>当前第 " + currentPage + " 页/共 " + totalPages + " 页</span>")
            //.Append(currentPage == startPage ? "<span class=\"pagerPage currentPage pagerPrefix\"> 首页 </span>" : string.Format("<a href='#' onclick='Query({0});' class='pagerPage firstPage pagerPrefix'>首页</a>",startPage)),
            //(seed, page) =>
            //{
                
            //    string style = "pagerPage";
            //    if (page == startPage)
            //        style += " firstPage";
            //    if (page == totalPages)
            //        style += " lastPage";
               
            //    if (page == currentPage)
            //        seed.AppendFormat("<span class=\"pagerPage currentPage\">{0}</span>", page);
            //    else
            //        seed.AppendFormat("<a href='#' onclick='Query({0});' class='{1}'>{0}</a>", page, style);
            //    return seed;
            //});

            //html.Append(currentPage == totalPages ? "<span class=\"pagerPage currentPage pagerSubfix\"> 末页 </span>" : string.Format("<a href='#' class='pagerPage lastPage pagerSubfix' onclick='Query({0})'>末页</a>", totalPages))
            //    .Append(@"</div>");
            StringBuilder html = new StringBuilder();
            if (currentPage==1)
            {
                html.AppendFormat("<span class=\"pagerPage currentPage pagerPrefix\"> 首页 </span>");
            }
            else
            {
                html.Append(string.Format("<a href='#' onclick='Query({0});' class='pagerPage firstPage pagerPrefix'>首页</a>", startPage));
                if(currentPage<=7)
                {
                    //html.Append(string.Format("<a href='#' onclick='Query({0});' class='pagerPage firstPage pagerPrefix'>首页</a>", startPage));
                    for(int i=1;i<=7;i++)
                    {

                    }
                }
            }

            return MvcHtmlString.Create(html.ToString());
        }
    }
}